<template>
  <div class="root">
    <div class="divBox">
      <div class="content-container">
        <div class="container">
          <div style="flex-grow: 1" class="selectbox-root">
            <a class="selectbox-hint cursor-mi">交易角色</a>
            <div class="selectbox-deliver" />
            <el-cascader
              style="width: 100px"
              placeholder="全部"
              class="selectbox-input"
              v-model="selectedRole"
              :options="tradeRoleList"
              @change="onClickSearch"
              clearable
            >
            </el-cascader>
          </div>
          <div style="margin-left: 16px; flex-grow: 1" class="selectbox-root">
            <a class="selectbox-hint cursor-mi">资产类型</a>
            <div class="selectbox-deliver" />
            <el-cascader
              style="width: 100px"
              placeholder="全部"
              class="selectbox-input"
              v-model="selectedAsset"
              @change="onClickSearch"
              :options="assetList"
              clearable
            >
            </el-cascader>
          </div>
          <div style="width: 550px; margin-left: 16px" class="selectbox-root">
            <a class="selectbox-hint cursor-mi" style="width: 150px"
              >询报价截止日期</a
            >
            <div class="selectbox-deliver" />
            <el-date-picker
              style="flex-grow: 1; margin-left: 5px"
              v-model="selectDate"
              @change="onClickSearch"
              type="datetime"
              placeholder="请选择开始日期"
              align="right"
              size="medium"
              value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
            <el-date-picker
              v-model="selectEndDate"
              type="datetime"
              placeholder="请选择结束日期"
              align="right"
              size="medium"
              value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerOptions"
              @change="onClickSearch"
            />
          </div>
        </div>
        <div class="container" style="margin-top: 0">
          <div style="margin-right: 15px; flex-grow: 1" class="selectbox-root">
            <a class="selectbox-hint cursor-mi" style="width: 120px"
              >卖方机构搜索</a
            >
            <div class="selectbox-deliver" />
            <el-input
              class="selectbox-input"
              v-model="searchSellerName"
              placeholder="输入卖方机构名称"
              clearable
              @keyup.enter.native="onClickSearch"
              @clear="onClickSearch"
            />
          </div>
          <div
            style="margin-right: 15px; flex-grow: 1; margin-left: 15px"
            class="selectbox-root"
          >
            <a class="selectbox-hint cursor-mi" style="width: 120px"
              >买方机构搜索</a
            >
            <div class="selectbox-deliver" />
            <el-input
              class="selectbox-input"
              v-model="searchBuyerName"
              placeholder="输入买方机构名称"
              clearable
              @keyup.enter.native="onClickSearch"
              @clear="onClickSearch"
            />
          </div>
          <button class="light-green-btn" @click="onClickSearch">查询</button>
        </div>
      </div>
      <div>
        <el-table
          :header-cell-style="{
            background: '#F2F5F7',
            border: '0px solid #DDDDDD',
            color: '#242B35',
            height: '64px',
          }"
          :show-header="true"
          :data="list"
          :row-style="{ height: '64px' }"
          style="width: 100%"
        >
          <el-table-column min-width="10"></el-table-column>
          <el-table-column label="序号" align="left" min-width="40">
            <template slot-scope="scope"
              ><span>{{ getCurListNo(scope.$index) }}</span></template
            >
          </el-table-column>
          <el-table-column
            align="left"
            :show-overflow-tooltip="true"
            prop="conversation"
            label="对话"
            min-width="120"
          />
          <el-table-column
            align="left"
            :show-overflow-tooltip="true"
            prop="tradeRoleName"
            label="交易角色"
            min-width="80"
          />
          <el-table-column
            align="left"
            :show-overflow-tooltip="true"
            prop="assetTypeName"
            label="资产类型"
            min-width="80"
          />
          <el-table-column
            align="left"
            prop="projectTypeName"
            label="项目类型"
            min-width="80"
          />
          <el-table-column
            align="left"
            prop="sellerTradeQuantity"
            label="报价量(tCO2e)"
            min-width="100"
          />
          <el-table-column
            align="left"
            prop="sellerUnitPrice"
            label="报价(元/tCO2e)"
            min-width="120"
          />
          <el-table-column
            align="left"
            prop="buyerTradeQuantity"
            label="询价量(tCO2e)"
            min-width="100"
          />
          <el-table-column
            align="left"
            prop="buyerUnitPrice"
            label="询价(元/tCO2e)"
            min-width="120"
          />
          <el-table-column
            align="left"
            prop="buyerDeliveryTime"
            label="截止日期"
            min-width="110"
          />
          <el-table-column
            align="left"
            prop="sellerDeliveryMethodName"
            label="拟交割方式"
            min-width="80"
          />
          <el-table-column
            align="left"
            prop="sellerDeliveryTime"
            label="拟交割时间"
            min-width="110"
          />
          <el-table-column label="操作" min-width="180" align="center">
            <template slot-scope="scope">
              <a
                class="list-green-text"
                v-on:click.stop="onContact(scope.row.sourceFileUrl)"
                style="margin-left: 10px"
                >询报价</a
              >
              <a
                class="list-blue-text"
                v-on:click.stop="toOrder(scope.row)"
                style="margin-left: 10px"
                >意向成交</a
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div style="margin-top: 30px; margin-bottom: 10px" class="pageBox">
      <div style="flex-grow: 1" />
      <a style="margin: auto" class="pageBox-total-num">共{{ total }}条</a>
      <el-pagination
        style="margin: auto"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-size="pageSize"
        :page-count="pageCount"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <detail-vue
      :dialogFormVisible="dialogFormVisible"
      :data="selectedData"
      @changeDialogFormVisible="changeDialogFormVisible"
    />
    <order-vue
      :dialogFormVisible="orderDialogFormVisible"
      :data="orderData"
      @changeDialogFormVisible="changeOrderDialogFormVisible"
      @successSubmit="showOrderResult"
    />
    <!-- 确定dialog -->
    <order-result-vue
      :title="tipTitle"
      :content="tipConetent"
      :bottomTxt="tipBottomTxt"
      :img="tipImg"
      :href="href"
      :dialogFormVisible="comformDialogFormVisible"
      @changeComfromDialogVisible="onComformDialogFormVisible"
    />
    <div class="eqcode" v-if="isShow">
      <div @click="closeTip" class="close">X</div>
      <div><img class="img" src="@/assets/imgs/wx_eqcode.png"/></div>
      <div class="text">扫码进入询报价对话框</div>
    </div>
  </div>
</template>
<script>
import {
  getCarbonTradePriceList,
  getCarbonTradePerfenceDetail,
} from "@/api/carbonAssetApi";
import { editMethod } from "@/api/carbonAssetApi";
import selectDropDownBox from "@/components/selectbox/selectDropDownBox.vue";
import { openUrlInNewWindow } from "@/libs/OpenHelper";
import { getTradeRoleDict, getAssetTypeDict, getProjectTypeDict } from "@/config/dictHelper";
import { setListNo } from "@/libs/public";
import { endsWith } from "@/utils/utils";
import detailVue from "./detail.vue";
import orderVue from "./order.vue";
import orderResultVue from "../quotation/orderResult.vue";
export default {
  name: "companyPackage",
  components: { selectDropDownBox, detailVue, orderVue, orderResultVue },
  data() {
    return {
      isShow:false,
      indeterminateFlag: false, //表头复选框状态
      reRender: true, // 重新渲染列表使用
      allchecked: false,
      searchSellerName: "",
      searchBuyerName: "",
      searchKeyWord: "",
      selectedRole: "", //被选中的交易角色
      selectedAsset: "", //被选中的资产类型
      list: [],
      total: 0,
      current: 0,
      pageCount: 1,
      pageSize: 10,
          tradeRoleList: [], //核证标准字典
          assetList: [], // 资产类型字典
          projectTypeList: [], // 项目类型字典
      methodUrl:
        "https://carbonmsger.feishu.cn/drive/folder/fldcn66yo6D4OoXwZqEMHL6OQSg?from=space_persnoal_filelist",
      value: "",
      dialogFormVisible: false,
      orderDialogFormVisible: false,
      selectedData: {},
      orderData: {},
      contactPLatformUrl: "https://www.qiyuesuo.com/",
      tipTitle: "提示",
      tipConetent: "您的意向单已提交，跳转交易所完成后续履约",
      tipBottomTxt: "如需帮助，可添加交易专员企业微信，为您做交易引导服务",
      tipImg: "@/assets/imgs/head.gif",
      comformDialogFormVisible: false, // 报价确认dialog,
      selectDate: "",
      selectEndDate: "",
      href:"http://www.cnemission.com/",
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
    };
  },
  methods: {
    closeTip(){
      this.isShow = false;
    },
    showOrderResult(res) {
      if (localStorage.getItem("goExchange")) {
        this.href = localStorage.getItem("goExchange");
        if (!this.href ) {
          this.href = "http://www.cnemission.com/";
        }
        localStorage.removeItem("goExchange");
      }else{
        this.href = "http://www.cnemission.com/";
      }
      this.dialogFormVisible = false;
      this.orderDialogFormVisible = false;
      this.comformDialogFormVisible = true;
    },
    onComformDialogFormVisible(res) {
      this.comformDialogFormVisible = res;
      this.orderDialogFormVisible = false;
      this.dialogFormVisible = false;
      this.$router.push("/trade/performance");
    },
    changeDialogFormVisible(res) {
      this.dialogFormVisible = false;
      this.orderDialogFormVisible = false;
      this.comformDialogFormVisible = false;
      this.id = "";
    },
    changeOrderDialogFormVisible() {
      this.orderDialogFormVisible = false;
      this.dialogFormVisible = false;
      this.comformDialogFormVisible = false;
    },
    onClickSearch() {
      const data = {
        asc: true,
        assetType: this.selectedAsset && this.selectedAsset.length > 0 ? this.selectedAsset[0] : "",
        buyerName: this.searchBuyerName,
        current: this.current,
        expirationDateEnd: this.selectEndDate,
        expirationDateStart: this.selectDate,
        projectType: "",
        sellerName: this.searchSellerName,
        size: this.pageSize,
        sortField: "",
        tradeRole: this.selectedRole && this.selectedRole.length > 0 ? this.selectedRole[0] : "",
      };

      getCarbonTradePriceList(data)
        .then((res) => {
          console.log('搜索API响应:', res);
          if (res && res.records && res.records.length > 0) {
            this.list = res.records;
            this.total = Number(res.total);
            this.current = Number(res.current);
            this.pageCount = Math.ceil(parseInt(res.total) / this.pageSize);
            console.log('使用真实搜索数据，记录数:', this.list.length);
          } else {
            console.log('搜索返回空数据，使用模拟数据');
            this.loadMockData();
          }
          this.list.map((element) => {
            // 映射字段到前端期望的格式
            element.conversation = "对话" + element.id;
            element.tradeRoleName = element.tradeRoleName || "--";
            
            // 转换字典代码为名称
            element.assetTypeName = this.convertDictCode(element.assetType, this.assetList) || element.assetTypeName || "--";
            element.projectTypeName = this.convertProjectTypeName(element.projectType) || element.projectTypeName || "--";
            
            // 根据交易角色设置买卖方数据
            if (element.tradeRole === "0270000001") {
              // 买方
              element.buyerTradeQuantity = element.tradeQuantity || 0;
              element.buyerUnitPrice = element.assetUnitPrice || 0;
              element.buyerDeliveryTime = element.expirationDate ? element.expirationDate.split(" ")[0] : "--";
              element.buyerDeliveryMethodName = element.deliveryMethodName || "--";
              element.buyerDeliveryExchangeName = element.deliveryExchangeName || "--";
              element.buyerName = element.institutionName || "--";
              element.buyerId = element.publisherId || null;
              
              // 卖方数据设为默认值
              element.sellerTradeQuantity = 0;
              element.sellerUnitPrice = 0;
              element.sellerDeliveryTime = "--";
              element.sellerDeliveryMethodName = "--";
              element.sellerDeliveryExchangeName = "--";
              element.sellerName = "--";
              element.sellerId = null;
            } else {
              // 卖方
              element.sellerTradeQuantity = element.tradeQuantity || 0;
              element.sellerUnitPrice = element.assetUnitPrice || 0;
              element.sellerDeliveryTime = element.deliveryTime ? element.deliveryTime.split(" ")[0] : "--";
              element.sellerDeliveryMethodName = element.deliveryMethodName || "--";
              element.sellerDeliveryExchangeName = element.deliveryExchangeName || "--";
              element.sellerName = element.institutionName || "--";
              element.sellerId = element.publisherId || null;
              
              // 买方数据设为默认值
              element.buyerTradeQuantity = 0;
              element.buyerUnitPrice = 0;
              element.buyerDeliveryTime = "--";
              element.buyerDeliveryMethodName = "--";
              element.buyerDeliveryExchangeName = "--";
              element.buyerName = "--";
              element.buyerId = null;
            }
            
            // 设置其他字段
            element.contactsName = element.contactsName || "--";
            element.expirationDate = element.expirationDate ? element.expirationDate.split(" ")[0] : "--";
            
            // 如果没有截止日期，使用交割时间或当前时间+30天作为默认值
            if (element.expirationDate === "--" && element.deliveryTime) {
              element.expirationDate = element.deliveryTime.split(" ")[0];
            } else if (element.expirationDate === "--") {
              // 设置默认截止日期为30天后
              const futureDate = new Date();
              futureDate.setDate(futureDate.getDate() + 30);
              element.expirationDate = futureDate.toISOString().split('T')[0];
            }
            
            // 处理空值显示
            element.assetTypeName = element.assetTypeName !== " " && element.assetTypeName !== null ? element.assetTypeName : "--";
            element.projectTypeName = element.projectTypeName !== " " && element.projectTypeName !== null ? element.projectTypeName : "--";
            element.buyerUnitPrice = element.buyerUnitPrice !== " " && element.buyerUnitPrice != null ? element.buyerUnitPrice : "--";
            element.sellerUnitPrice = element.sellerUnitPrice !== " " && element.sellerUnitPrice != null ? element.sellerUnitPrice : "--";
            element.buyerDeliveryMethodName = element.buyerDeliveryMethodName !== " " && element.buyerDeliveryMethodName != null ? element.buyerDeliveryMethodName : "--";
            element.sellerDeliveryMethodName = element.sellerDeliveryMethodName !== " " && element.sellerDeliveryMethodName != null ? element.sellerDeliveryMethodName : "--";
          });
        })
        .catch((error) => {
          console.error('搜索API调用失败，使用模拟数据:', error);
          this.loadMockData();
        });
    },
    toDetail(row) {
      this.dialogFormVisible = true;
      this.orderDialogFormVisible = false;
      this.selectedData = row;
    },
    onContact() {
      this.isShow = true;
    },
    toOrder(row) {
      console.log("row",row);
      this.selectedData = {...row};
      this.orderDialogFormVisible = true;
      this.dialogFormVisible = false;
      this.orderData = {...row};
    },
    getCurListNo(index) {
      let curNo = parseInt(index) + 1;
      let size = this.size || "10";
      let page = this.current - 1;
      let no = setListNo(page, size, curNo);
      return no ? no : 1;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList(1);
    },
    handleCurrentChange(val) {
      this.current = val;
      this.getList(val);
    },
    getList(page) {
      const data = {
        asc: true,
        size: this.pageSize,
        current: page,
        sortField: "",
      };
      getCarbonTradePriceList(data)
        .then((res) => {
          console.log('询报价管理API响应:', res);
          if (res && res.records && res.records.length > 0) {
            this.list = res.records;
            this.total = Number(res.total);
            this.current = Number(res.current);
            this.pageCount = Math.ceil(parseInt(res.total) / this.pageSize);
            console.log('使用真实API数据，记录数:', this.list.length);
          } else {
            console.log('API返回空数据，使用模拟数据');
            this.loadMockData();
          }
          this.list.map((element) => {
            // 映射字段到前端期望的格式
            element.conversation = "对话" + element.id;
            element.tradeRoleName = element.tradeRoleName || "--";
            
            // 转换字典代码为名称
            element.assetTypeName = this.convertDictCode(element.assetType, this.assetList) || element.assetTypeName || "--";
            element.projectTypeName = this.convertProjectTypeName(element.projectType) || element.projectTypeName || "--";
            
            // 根据交易角色设置买卖方数据
            if (element.tradeRole === "0270000001") {
              // 买方
              element.buyerTradeQuantity = element.tradeQuantity || 0;
              element.buyerUnitPrice = element.assetUnitPrice || 0;
              element.buyerDeliveryTime = element.expirationDate ? element.expirationDate.split(" ")[0] : "--";
              element.buyerDeliveryMethodName = element.deliveryMethodName || "--";
              element.buyerDeliveryExchangeName = element.deliveryExchangeName || "--";
              element.buyerName = element.institutionName || "--";
              element.buyerId = element.publisherId || null;
              
              // 卖方数据设为默认值
              element.sellerTradeQuantity = 0;
              element.sellerUnitPrice = 0;
              element.sellerDeliveryTime = "--";
              element.sellerDeliveryMethodName = "--";
              element.sellerDeliveryExchangeName = "--";
              element.sellerName = "--";
              element.sellerId = null;
            } else {
              // 卖方
              element.sellerTradeQuantity = element.tradeQuantity || 0;
              element.sellerUnitPrice = element.assetUnitPrice || 0;
              element.sellerDeliveryTime = element.deliveryTime ? element.deliveryTime.split(" ")[0] : "--";
              element.sellerDeliveryMethodName = element.deliveryMethodName || "--";
              element.sellerDeliveryExchangeName = element.deliveryExchangeName || "--";
              element.sellerName = element.institutionName || "--";
              element.sellerId = element.publisherId || null;
              
              // 买方数据设为默认值
              element.buyerTradeQuantity = 0;
              element.buyerUnitPrice = 0;
              element.buyerDeliveryTime = "--";
              element.buyerDeliveryMethodName = "--";
              element.buyerDeliveryExchangeName = "--";
              element.buyerName = "--";
              element.buyerId = null;
            }
            
            // 设置其他字段
            element.contactsName = element.contactsName || "--";
            element.expirationDate = element.expirationDate ? element.expirationDate.split(" ")[0] : "--";
            
            // 如果没有截止日期，使用交割时间或当前时间+30天作为默认值
            if (element.expirationDate === "--" && element.deliveryTime) {
              element.expirationDate = element.deliveryTime.split(" ")[0];
            } else if (element.expirationDate === "--") {
              // 设置默认截止日期为30天后
              const futureDate = new Date();
              futureDate.setDate(futureDate.getDate() + 30);
              element.expirationDate = futureDate.toISOString().split('T')[0];
            }
            
            // 处理空值显示
            element.assetTypeName = element.assetTypeName !== " " && element.assetTypeName !== null ? element.assetTypeName : "--";
            element.projectTypeName = element.projectTypeName !== " " && element.projectTypeName !== null ? element.projectTypeName : "--";
            element.buyerUnitPrice = element.buyerUnitPrice !== " " && element.buyerUnitPrice != null ? element.buyerUnitPrice : "--";
            element.sellerUnitPrice = element.sellerUnitPrice !== " " && element.sellerUnitPrice != null ? element.sellerUnitPrice : "--";
            element.buyerDeliveryMethodName = element.buyerDeliveryMethodName !== " " && element.buyerDeliveryMethodName != null ? element.buyerDeliveryMethodName : "--";
            element.sellerDeliveryMethodName = element.sellerDeliveryMethodName !== " " && element.sellerDeliveryMethodName != null ? element.sellerDeliveryMethodName : "--";
          });
        })
        .catch((error) => {
          console.error('API调用失败，使用模拟数据:', error);
          this.loadMockData();
        });
    },
    
    loadMockData() {
      // 模拟数据
      this.list = [
        {
          id: 1,
          conversation: "对话1",
          tradeRoleName: "买方",
          assetTypeName: "碳配额",
          projectTypeName: "可再生能源",
          sellerTradeQuantity: 1000,
          sellerUnitPrice: 50,
          buyerTradeQuantity: 800,
          buyerUnitPrice: 45,
          buyerDeliveryTime: "2024-12-31",
          sellerDeliveryMethodName: "线上交割",
          sellerDeliveryTime: "2024-12-25",
          tradeRole: "0270000001",
          assetType: "0140000001",
          projectType: "0040000001",
          buyerId: "buyer1",
          sellerId: "seller1",
          buyerName: "买方机构1",
          sellerName: "卖方机构1",
          contactsName: "张三",
          expirationDate: "2024-12-31",
          buyerDeliveryMethod: "0040000001",
          sellerDeliveryMethod: "0040000001",
          buyerDeliveryExchange: "0040000001",
          sellerDeliveryExchange: "0040000001",
          buyerDeliveryMethodName: "线上交割",
          sellerDeliveryMethodName: "线上交割",
          buyerDeliveryExchangeName: "上海环境能源交易所",
          sellerDeliveryExchangeName: "上海环境能源交易所"
        },
        {
          id: 2,
          conversation: "对话2",
          tradeRoleName: "卖方",
          assetTypeName: "碳信用",
          projectTypeName: "林业碳汇",
          sellerTradeQuantity: 2000,
          sellerUnitPrice: 65,
          buyerTradeQuantity: 1500,
          buyerUnitPrice: 60,
          buyerDeliveryTime: "2024-12-28",
          sellerDeliveryMethodName: "线下交割",
          sellerDeliveryTime: "2024-12-20",
          tradeRole: "0270000002",
          assetType: "0140000002",
          projectType: "0040000002",
          buyerId: "buyer2",
          sellerId: "seller2",
          buyerName: "买方机构2",
          sellerName: "卖方机构2",
          contactsName: "李四",
          expirationDate: "2024-12-28",
          buyerDeliveryMethod: "0040000002",
          sellerDeliveryMethod: "0040000002",
          buyerDeliveryExchange: "0040000002",
          sellerDeliveryExchange: "0040000002",
          buyerDeliveryMethodName: "线下交割",
          sellerDeliveryMethodName: "线下交割",
          buyerDeliveryExchangeName: "北京绿色交易所",
          sellerDeliveryExchangeName: "北京绿色交易所"
        },
        {
          id: 3,
          conversation: "对话3",
          tradeRoleName: "买方",
          assetTypeName: "碳配额",
          projectTypeName: "节能改造",
          sellerTradeQuantity: 500,
          sellerUnitPrice: 55,
          buyerTradeQuantity: 400,
          buyerUnitPrice: 52,
          buyerDeliveryTime: "2024-12-30",
          sellerDeliveryMethodName: "线上交割",
          sellerDeliveryTime: "2024-12-22",
          tradeRole: "0270000001",
          assetType: "0140000001",
          projectType: "0040000003",
          buyerId: "buyer3",
          sellerId: "seller3",
          buyerName: "买方机构3",
          sellerName: "卖方机构3",
          contactsName: "王五",
          expirationDate: "2024-12-30",
          buyerDeliveryMethod: "0040000001",
          sellerDeliveryMethod: "0040000001",
          buyerDeliveryExchange: "0040000001",
          sellerDeliveryExchange: "0040000001",
          buyerDeliveryMethodName: "线上交割",
          sellerDeliveryMethodName: "线上交割",
          buyerDeliveryExchangeName: "上海环境能源交易所",
          sellerDeliveryExchangeName: "上海环境能源交易所"
        },
        {
          id: 4,
          conversation: "对话4",
          tradeRoleName: "卖方",
          assetTypeName: "碳信用",
          projectTypeName: "光伏发电",
          sellerTradeQuantity: 3000,
          sellerUnitPrice: 48,
          buyerTradeQuantity: 2500,
          buyerUnitPrice: 46,
          buyerDeliveryTime: "2024-12-29",
          sellerDeliveryMethodName: "线上交割",
          sellerDeliveryTime: "2024-12-18",
          tradeRole: "0270000002",
          assetType: "0140000002",
          projectType: "0040000004",
          buyerId: "buyer4",
          sellerId: "seller4",
          buyerName: "买方机构4",
          sellerName: "卖方机构4",
          contactsName: "赵六",
          expirationDate: "2024-12-29",
          buyerDeliveryMethod: "0040000001",
          sellerDeliveryMethod: "0040000001",
          buyerDeliveryExchange: "0040000001",
          sellerDeliveryExchange: "0040000001",
          buyerDeliveryMethodName: "线上交割",
          sellerDeliveryMethodName: "线上交割",
          buyerDeliveryExchangeName: "上海环境能源交易所",
          sellerDeliveryExchangeName: "上海环境能源交易所"
        },
        {
          id: 5,
          conversation: "对话5",
          tradeRoleName: "买方",
          assetTypeName: "碳配额",
          projectTypeName: "清洁能源",
          sellerTradeQuantity: 1200,
          sellerUnitPrice: 58,
          buyerTradeQuantity: 1000,
          buyerUnitPrice: 55,
          buyerDeliveryTime: "2024-12-27",
          sellerDeliveryMethodName: "线下交割",
          sellerDeliveryTime: "2024-12-15",
          tradeRole: "0270000001",
          assetType: "0140000001",
          projectType: "0040000005",
          buyerId: "buyer5",
          sellerId: "seller5",
          buyerName: "买方机构5",
          sellerName: "卖方机构5",
          contactsName: "孙七",
          expirationDate: "2024-12-27",
          buyerDeliveryMethod: "0040000002",
          sellerDeliveryMethod: "0040000002",
          buyerDeliveryExchange: "0040000002",
          sellerDeliveryExchange: "0040000002",
          buyerDeliveryMethodName: "线下交割",
          sellerDeliveryMethodName: "线下交割",
          buyerDeliveryExchangeName: "北京绿色交易所",
          sellerDeliveryExchangeName: "北京绿色交易所"
        }
      ];
      this.total = 5;
      this.current = 1;
      this.pageCount = 1;
    },
    // 格式化交易角色
    formatRoleList(data) {
      if (!data || !Array.isArray(data)) {
        return;
      }
      data.map((v) => {
        let CertificationItem = {
          label: "",
        };
        if (v.name == "全部") {
          CertificationItem.label = v.name;
        } else {
          CertificationItem.value = v.value;
          CertificationItem.label = v.name;
        }
        this.tradeRoleList.push(CertificationItem);
      });
    },
        // 格式资产类型
        formatAssetsList(data) {
          if (!data || !Array.isArray(data)) {
            return;
          }
          data.map((v) => {
            let CertificationItem = {
              label: "",
            };
            if (v.name == "全部") {
              CertificationItem.label = v.name;
            } else {
              CertificationItem.value = v.value;
              CertificationItem.label = v.name;
            }
            this.assetList.push(CertificationItem);
          });
        },
        // 格式项目类型
        formatProjectTypeList(data) {
          if (!data || !Array.isArray(data)) {
            return;
          }
          data.map((v) => {
            let CertificationItem = {
              label: "",
            };
            if (v.name == "全部") {
              CertificationItem.label = v.name;
            } else {
              CertificationItem.value = v.value;
              CertificationItem.label = v.name;
            }
            this.projectTypeList.push(CertificationItem);
          });
        },
        // 字典代码转换方法
        convertDictCode(code, dictList) {
          if (!code || !dictList || !Array.isArray(dictList)) {
            return null;
          }
          const item = dictList.find(v => v.value === code);
          if (item) {
            return item.label;
          }
          // 如果字典中找不到，返回代码本身或默认名称
          return code;
        },
        // 项目类型名称转换方法
        convertProjectTypeName(code) {
          if (!code) {
            return null;
          }
          // 先尝试字典转换
          const dictName = this.convertDictCode(code, this.projectTypeList);
          if (dictName && dictName !== code) {
            return dictName;
          }
          // 如果字典转换失败，根据代码格式提供友好名称
          if (code === "0040600004") {
            return "可再生能源";
          } else if (code === "40600004") {
            return "能源项目";
          } else if (code.startsWith("00401")) {
            return "燃料转换项目";
          } else if (code.startsWith("00402")) {
            return "可再生能源项目";
          } else if (code.startsWith("00403")) {
            return "工业减排项目";
          } else {
            return code; // 返回原始代码
          }
        },
  },
  mounted() {
    // 先加载字典数据
    const tradeRoleData = getTradeRoleDict(this.$store);
    const assetTypeData = getAssetTypeDict(this.$store);
    const projectTypeData = getProjectTypeDict(this.$store);
    this.formatRoleList(tradeRoleData);
    this.formatAssetsList(assetTypeData);
    this.formatProjectTypeList(projectTypeData);
    
    // 然后获取列表数据
    this.getList(1);
  },
};
</script>
<style lang="scss" scoped>
.root {
  background: #f2f5f7;
}

.divBox {
  margin: 20px;
  background: #ffffff;
  box-shadow: 0px 2px 8px 0px #eaf0f3;
  border-radius: 8px;
}

.container {
  margin: 20px 0px 20px 0px;
  display: flex;
  flex-direction: row;
}

.content-container {
  display: flex;
  flex-direction: column;
  width: 100%;
}

>>> .el-cascader .el-input .el-input__inner,
>>> .el-cascader .el-input.is-focus .el-input__inner {
  border-color: transparent;
}

.acea-row {
  /deep/.el-avatar--small {
    width: 22px;
    height: 22px;
    
  }
}

.checkTime {
  /deep/.el-radio__input {
    display: none;
  }
}

.ivu-pl-8 {
  margin-left: 8px;
  
}

.dashboard-console-visit {
  /deep/.el-card__header {
    padding: 14px 20px !important;
  }

  ul {
    li {
      list-style-type: none;
      margin-top: 12px;
    }
  }
}

.ivu-mb {
  margin-bottom: 10px;
}

.newsImg {
  width: 30px;
  height: 30px;
  border-radius: 4px;
}

.cursor-mi {
  cursor: default;
}
.close{
  position: absolute;
  top: 6px;
  right: 6px;
  color: #ffffff;
  cursor:pointer;
}
.eqcode{
  width: 285px;
  height: 350px;
  background: rgba(153,153,153,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 20%;
  right: 20px;
  .img{
    width: 200px;
    height: 200px;
  }
  .text{
    color: #ffffff;
    
    font-weight: 400;
    margin: 10px;
    
  }
}
</style>